﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Windows.Controls;

namespace Dynamic_UI_Framework
{
    [Export(typeof(TabItemRegionAdapter))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class TabItemRegionAdapter : AdapterBase<IRegion, TabItem>
    {
        protected override void Adapt(IRegion codon, TabItem target)
        {
            Region r = codon as Region;
            r.Target = target;

            target.ContextMenu = new ContextMenu();
            foreach (var item in r.GetMenuItem())
            {
                target.ContextMenu.Items.Add(item);
            }


            r.CurrentItemChanged += (s, e) =>
            {
                target.Content = r.CurrentItem.Target;
            };


        }

        protected override IRegion Create()
        {
            return new Region();
        }
    }
}
